//
//  WSLanguage.m
//  CharonTVProject
//
//  Created by xunruiIOS on 2023/11/17.
//

#import "WSLanguage.h"
#import "AppDelegate.h"

static NSString *const WSUserLanguageKey = @"WSUserLanguageKey";

@implementation WSLanguage

+ (void)setUserLanguageType:(NSInteger)languageType {
    appConfig.laType = languageType;
    NSArray * languageArray = @[@"",@"zh-Hans", @"en", @"zh-Hant", @""];
    NSString * language = languageArray[languageType];
    [WSLanguage setUserLanguage:language];
}

+ (void)setUserLanguage:(NSString *)userLanguage
{
    //跟随手机系统
    if (!userLanguage.length) {
        [self resetSystemLanguage];
        return;
    }
    //用户自定义
    [appUserDefaults setValue:userLanguage forKey:WSUserLanguageKey];
    [appUserDefaults setValue:@[userLanguage] forKey:@"AppleLanguages"];
    [appUserDefaults synchronize];
    [((AppDelegate*)([UIApplication sharedApplication].delegate)) reloadMain];
}

+ (NSString *)userLanguage
{
    return [appUserDefaults valueForKey:WSUserLanguageKey];
}

/**
 重置系统语言
 */
+ (void)resetSystemLanguage
{
    [appUserDefaults removeObjectForKey:WSUserLanguageKey];
    [appUserDefaults setValue:nil forKey:@"AppleLanguages"];
    [appUserDefaults synchronize];
}


@end
